import { Base } from '../../utils/base.js'

class Rechange extends Base {
  constructor() {
    super();
  }

  /*提交充值数据*/
  rechange(param, callback) {
    var that = this;
    var allParams = {
      url: 'pay/recharge',
      data: param,
      type: 'post',
      sCallback: function (data) {
        if (data.status == 1) {
          var data = data.items;
          var timeStamp = data.timeStamp;
          if (timeStamp) { //可以支付
            wx.requestPayment({
              'timeStamp': timeStamp.toString(),
              'nonceStr': data.nonceStr,
              'package': data.package,
              'signType': data.signType,
              'paySign': data.paySign,
              success: function () {
                callback && callback(2);
              },
              fail: function () {
                callback && callback(1);
              }
            });
          } else {
            callback && callback(0);
          }
        } else {
          callback && callback(data);
        }
      }
    };
    this.request(allParams);
  }

}
export { Rechange }